package cn.edu.scau.cmi.yangzhengkai.client.classicsDesignPattern;

import java.util.Scanner;

import cn.edu.scau.cmi.yangzhengkai.factory.BeefFactory;
import cn.edu.scau.cmi.yangzhengkai.factory.ChickenFactory;
import cn.edu.scau.cmi.yangzhengkai.factory.MeatFactory;
import cn.edu.scau.cmi.yangzhengkai.factory.PorkFactory;
import cn.edu.scau.cmi.yangzhengkai.simpleFactoryMethod.domain.Meat;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class FactoryClient extends Application{

	@Override
	public void start(Stage primaryStage){
		
		FlowPane fp = new FlowPane();
		HBox hb1 = new HBox();
		HBox hb2 = new HBox();
		Text t = new Text("Please select which kind of meat you want to eat:");
		ComboBox<String> cb = new ComboBox<String>();
		Button bu = new Button("Yes");
		Label lb = new Label();
		
		t.setStyle("-fx-font-size:18");
		cb.setStyle("-fx-font-size:16");
		lb.setStyle("-fx-font-size:18");
		cb.getItems().addAll("beef","chicken","pork");
		hb1.getChildren().addAll(t,cb,bu);
		hb2.getChildren().add(lb);
		hb1.setMargin(t,new Insets(10, 0, 0, 20));
		hb1.setMargin(cb,new Insets(5, 5, 0, 5));
		hb1.setMargin(bu,new Insets(5, 0, 0, 0));
		hb2.setMargin(lb, new Insets(10, 0, 0, 20));
		fp.setOrientation(Orientation.VERTICAL);
		fp.getChildren().addAll(hb1,hb2);
		
		bu.setOnAction(new EventHandler<ActionEvent>() {
			
			@Override
			public void handle(ActionEvent event) {
				String meatType = cb.getValue();
				MeatFactory meatFactory = null; 
				Meat meat = null;
				switch (meatType) {
				case "beef":
					meatFactory = new BeefFactory(); 
					break;
				case "chicken":
					meatFactory = new ChickenFactory();
					break;
				case "pork":
					meatFactory = new PorkFactory();
					break;
				}
				meat = meatFactory.getMeat();
			    lb.setText(meat.cook());
				
			}
		});	
		
		Scene scene = new Scene(fp);
		primaryStage.setScene(scene);
		primaryStage.setWidth(800);
		primaryStage.setHeight(500);
		primaryStage.show();
	}
	
	public static void main(String[] args) {
		launch(args);
	}

}
